package drds.server.sqlparser.sqlobject.expression.binary;

/**
 * 二元操作符
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public enum BinaryOperator {
	/**
	 * 切分键
	 */
	PartitionKeyEq("=", 110), //
	PartitionKeyLessThan("<", 110), //
	PartitionKeyLessThanOrEqual("<=", 110), //
	PartitionKeyGreaterThan(">", 110), //
	PartitionKeyGreaterThanOrEqual(">=", 110), //
	//

	Union("union", 0), //
	//
	Add("+", 70), //
	Subtract("-", 70), //
	//
	NotEqual("!=", 110), //
	Equal("=", 110), //
	LessThan("<", 110), //
	LessThanOrEqual("<=", 110), //
	GreaterThan(">", 110), //
	GreaterThanOrEqual(">=", 110), //

	Like("like", 110), //
	NotLike("not like", 110), //

	Is("is", 110), //
	IsNot("is not", 110), //
	//
	And("and", 140), //
	Or("or", 160);
	public final String name;
	public final int priority;

	BinaryOperator() {
		this(null, 0);
	}

	BinaryOperator(String name, int priority) {
		this.name = name;
		this.priority = priority;
	}

	public String getName() {
		return this.name;
	}

	public int getPriority() {
		return this.priority;
	}

	public boolean isRelational() {
		switch (this) {

		case Like:
		case NotLike:
			//

		case Equal:
		case NotEqual:
			//
		case GreaterThan:
		case GreaterThanOrEqual:
			//
		case LessThan:
		case LessThanOrEqual:

			return true;
		default:
			return false;
		}
	}

	public boolean isAndOr() {
		return this == And || this == Or;
	}
}
